<?php
	include("initialize.php");
?>
<html> 
<head>
	<title> Success - New Class </title>
	<script>
	   function changeScreenSize(w,h)
		 {
		   window.resizeTo( w,h )
		 }
	</script>
</head>
<body onload="changeScreenSize(300,125)">
	<?php include ("write_functions.php");
	connect('localhost','root','','gradegriddatabase');
	
	$username = mysql_real_escape_string($_SESSION["username"]);
	$course = mysql_real_escape_string($_POST["course"]);
	$section = mysql_real_escape_string($_POST["section"]);
	$template = mysql_real_escape_string($_POST["template"]);
	$starttime = mysql_real_escape_string($_POST["start"]);
	$endtime = mysql_real_escape_string($_POST["end"]);
	$days = $_POST["days"];
	
	$accountid_query = sprintf("SELECT account_id FROM account WHERE username = '%s'",
		                        $username);
	$accountid_array = mysql_fetch_array(mysql_query($accountid_query));
	$accountid = mysql_real_escape_string($accountid_array["account_id"]);
	
	$courseid_query = sprintf("SELECT course_id FROM course WHERE course_name='%s'",
	                          $course);
	$ci_array = mysql_fetch_array(mysql_query($courseid_query));
	$courseid = intval($ci_array["course_id"]);
	
	$templateid_query = sprintf("SELECT template_id FROM template WHERE template_name='%s'",
	                            $template);
	$ti_array = mysql_fetch_array(mysql_query($templateid_query));
	$templateid = intval($ti_array["template_id"]);
	
	$class_name=$_POST['className'];
	createclass($courseid,$accountid,$templateid,$section);
	$classid_query = sprintf("SELECT class_id FROM class WHERE class_name='%s' AND course_id = '%s'",
	                         $section,
							 $courseid);
	$classid_array = mysql_fetch_array(mysql_query($classid_query));
	$classid = $classid_array["class_id"];
	
	$i = 0;
	$days_limit = count($days);
	
	while($i < $days_limit){
		createschedule($classid, "", $days[$i], $starttime, $endtime);
		$i++;
	}
	?>
	<h5>You have successfully created a class.</h5>
</body>
</html>